package vcp.client.GUI.mvc.model;

import vcp.client.interfaces.IObservable;
import vcp.client.request.UserLoginRequest;
import vcp.client.request.UserLogoutRequest;
import vcp.entity.User;
import vcp.enums.Screen;
/**
 * 
 * @author VCP team
 *<p>
 *login model
 *</p>
 *@see UIAbstractModel
 */
public class UILoginModel extends UIAbstractModel
{

	public UILoginModel ( IObservable model )
	{
		super(model);
	}

	/****************************************************************************************************************************
	 *** Public methods ***
	 ****************************************************************************************************************************/
	/**
	 * <p>
	 * verify if log in data is correct
	 * </p>
	 * @param id
	 * @param password
	 */
	public void verifyLogin ( Integer id, String password )
	{
		UserLoginRequest request = new UserLoginRequest(id, password);
		this.sendRequest(request, true);
	}
	/**
	 * Update user that log out
	 */
	public void performLogout ()
	{
		UserLogoutRequest request = new UserLogoutRequest();
		this.sendRequest(request, false);
		this.model.registerForUpdates(null);
	}

	/****************************************************************************************************************************
	 *** Observer methods ***
	 ****************************************************************************************************************************/
	@Override
	public void update ( Object data )
	{
		if ( data instanceof User )
		{
			Screen userScreen = ( (User) data ).getInitScreenType();
			this.controllerDelegate.loadMVCWithData(userScreen, data);
		}
	}

}
